#encoding: utf-8
require 'starling'

#测试使用
#模拟gps厂商的数据发送
class Gps
 
	attr_accessor :lng, :lat, :speed, :stop_time, :direction, :datetime
end 

 
p starling = Starling.new('localhost:22122')
 
gps1 = Gps.new
gps2 = Gps.new

gps11 = Gps.new
gps22 = Gps.new

i = 0
begin
  while true
    gps_data = {}

    gps1.lng = 121040000 + i
    gps1.lat = 37000120 + 1
    gps1.direction = 45
    gps1.datetime = Time.now
    gps11.lng = 121040100 + i
    gps11.lat = 37000220 + 1
    gps11.direction = 135
    gps11.datetime = Time.now

    gps_data["lk-001"] = [gps1, gps11]

    gps2.lng = 121120120 + 1
    gps2.lat = 36700120 + i
    gps2.direction = 45
    gps2.datetime = Time.now

    gps22.lng = 121120220 + 1
    gps22.lat = 36700220 + i
    gps22.direction = -45
    gps22.datetime = Time.now

    gps_data["lk-002"] = [gps2, gps22]

    starling.set('q_dispatcher', gps_data)
    sleep(1)
    puts "sending #{gps_data}"
    i = i + 200
  end
rescue => e
  puts "Exception in send:#{e.message}"
  retry
end

